package com.google.gwt.sample.dynatablerf.client.user.presenters;

import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.sample.dynatablerf.client.user.events.GoToCategoriaViewEvent;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.IsWidget;

public class MainPresenter {

	public interface MainDisplay extends IsWidget {

		HasWidgets getContainer();
	}

	private EventBus eventBus;
	private MainDisplay mainDisplay;

	public MainPresenter(EventBus eventBus, MainDisplay mainDisplay) {
		super();
		this.eventBus = eventBus;
		this.mainDisplay = mainDisplay;
	}

	public void go(HasWidgets hasWidgets) {
		hasWidgets.clear();
		hasWidgets.add(mainDisplay.asWidget());
		Scheduler.get().scheduleDeferred(new ScheduledCommand() {

			@Override
			public void execute() {
				eventBus.fireEvent(new GoToCategoriaViewEvent(mainDisplay
						.getContainer(), null));
			}
		});
	}

}
